<%--
 *  File:    DataClean.jsp
 *  @Author: Jamesli
 *  Date:    2010/07/21
 *
 *  Copyright (C) 2000 - 2010 Oval Technologies, Inc.
 *  All rights reserved. 
 *
 *  This software is the confidential and proprietary information of Oval 
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>

<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>     
<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>
<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.DataClean"); 

  //init param
  String strModuleName = "CM";
  String privilegeCode = "E0211";
  String contextPath = request.getContextPath();
%>
<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/FrmDefault.inc" %>
<%@ include file="/inc/PageDefault.inc" %>
<%@ include file="/inc/LocationDefault.inc" %>

<html>
<head>
<title>DataClean</title>
<PageFlow:CheckPageFlow pageName="p_datacleansummary"/>
<link rel="stylesheet" href="<%=contextPath %>/css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="<%=contextPath %>/css/<%= strLanguageCode %>/script.js"></script>
<script language="JavaScript" src="<%=contextPath %>/js/ScriptLib.js"></script>
<%@ include file="/inc/SummaryDivision.inc" %>
<script>
function page_checkall(){
	var allcheck = cform.checkall;
	var allfile = document.getElementsByName("fileids");
	for(var i = 0 ; i < allfile.length;i++){
		allfile[i].checked = allcheck.checked;
	}
}

function page_summary(actionvalue,orderbyname)
{
  var editform = summaryPrepare(cform,actionvalue,orderbyname);
  editform.action = "DataClean.jsp?<%= OvalTools.randomURL() %>";
  editform.target = "_self";
  isRunning = true;
  editform.submit();  
}

function page_detail(id){
  self.location.href = "DataCleanDetail.jsp?<%= OvalTools.randomURL() %>&datafileid=" + id + "&processtype=" + cform.processtype.value + "&datafrequency=" + cform.datafrequency.value;
}

var popwindow;

function page_checkstatus(id,aid){
	var processtype = cform.processtype.value;
	var checkstatus = document.getElementById(aid).innerText;
	if(popwindow!=null) popwindow.close();
	popwindow = window.open('CheckStatus.jsp?<%= OvalTools.randomURL() %>&fileid=' + id + '&processtype=' + processtype + '&checkstatus=' + checkstatus,'newwindow', 'height=400, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}

function page_setRegion(code,name)
{
  if(code != document.cform.regioncode.value)
  {
    document.cform.citycode.value = "";
    document.cform.cityname.value = "";
  }
  document.cform.regioncode.value = code;
  document.cform.regionname.value = name;
  if (popwindow != null)
    popwindow.close();
}

function page_selectProvince()
{
  if(popwindow!=null)
    popwindow.close();
  popwindow = window.open('<%=contextPath %>/masterdata/ogm/RegionSelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN','newwindow', 'height=250, width=500,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no');
}

function page_selectCity()
{
  var regioncode = document.cform.regioncode.value;
  if(regioncode=="" || regioncode==-1)
  {
    alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
    return;
  }
  if(popwindow!=null)
    popwindow.close();
  popwindow = window.open('<%=contextPath %>/masterdata/ogm/CitySelect.jsp?<%= OvalTools.randomURL() %>&languagecode=<%= strLanguageCode %>&countrycode=CN&regioncode=' + regioncode,'newwindow', 'height=250, width=400,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}

function page_setCity(code,name)
{
  document.cform.citycode.value = code;
  document.cform.cityname.value = name;
  if (popwindow != null)
    popwindow.close();
}

function page_setOrg(id,name,code)
{
  document.cform.parternerid.value = id;
  document.cform.parternercode.value = code;  
  document.cform.parternername.value = name;
  var remote = window.open("","newwindow");
  if (remote != null)
    remote.close();
}

function page_dataclean(){
	var allfile = document.getElementsByName("fileids");
	var idstr = "";
	for(var i = 0 ; i < allfile.length;i++){
		if(allfile[i].checked){
			idstr += "&fileids=" + allfile[i].value;
		}
	}
	if(idstr == ""){
		alert("<%= message.getMessageDesc("PLEASE_SELECT")%>");
		return;
	}

	var status = "height=400, width=500,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=yes";
    var url = "DataCleanRulePop.jsp?<%= OvalTools.randomURL() %>&processtype=" + cform.processtype.value + idstr;
    if(popwindow!=null)
        popwindow.close();
      popwindow = window.open(url,'newwindow', status);	 
}

function page_datacleanall(){
	var status = "height=400, width=500,top=100,left=100,toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=yes";
    var url = "DataCleanRulePop.jsp?<%= OvalTools.randomURL() %>&processtype=" + cform.processtype.value;
    if(popwindow!=null)
        popwindow.close();
      popwindow = window.open(url,'newwindow', status);	 
}

function page_changecleanrule(){
	if(cform.cleanrule.value == ""){
		cform.errorlevelshow.options[0].selected = true;
		cform.errorlevelshow.disabled = true;
	}else{
		cform.errorlevelshow.disabled = false;
	}
}

function page_changeRegion()
{
	var regioncode = cform.regioncode.value;
	page_cleanregionandcity();
	if(regioncode == "")return;
   var datahandler = new  DataHandler() ;
   datahandler.add_params("regioncode" , regioncode, 'String') ;
   datahandler.add_params("languagecode" , document.cform.languagecode.value, 'String') ;
   datahandler.getResult("regionname" ,"document.cform.regionname");
   datahandler.add_job("j_getregionbycode");
   datahandler.add_function("page_checkRegion()");
   datahandler.runDataHandler();
}

function page_checkRegion(){
	if(cform.regionname.value == ""){
		cform.regioncode.value = "";
	}
}

function page_changeCity()
{
	var regioncode = cform.regioncode.value;
	var citycode = cform.citycode.value;
	page_cleancity();
	if(citycode == "")return;
	if(isEmpty(regioncode))
	{
	  alert("<%= message.getMessageDesc("MUST_SELECT_FIRST",label.getLabelName("L_Province"))%>");
	  cform.citycode.value = "";
	  return;
	}
	var datahandler = new  DataHandler() ;
	datahandler.add_params("regioncode" , regioncode, 'String') ;
	datahandler.add_params("citycode" , citycode, 'String') ;
	datahandler.add_params("languagecode" , document.cform.languagecode.value, 'String') ;
	datahandler.getResult("cityname" ,"document.cform.cityname");
	datahandler.add_job("j_getcitybycode");
	datahandler.add_function("page_checkCity()");
	datahandler.runDataHandler();
}

function page_checkCity(){
	if(cform.cityname.value == ""){
		cform.citycode.value = "";
	}
}

function page_changeOrg()
{
	var parternercode = cform.parternercode.value;
	cform.parternername.value = "";
	cform.parternerid.value = "";
	if(parternercode == "")return;
	var datahandler = new  DataHandler() ;
	datahandler.add_params("orgcode" , parternercode, 'String') ;
	datahandler.getResult("orgname" ,"document.cform.parternername");
	datahandler.getResult("orgid" ,"document.cform.parternerid");
	datahandler.add_job("j_getorgbycode");
	datahandler.add_function("page_checkOrg()");
	datahandler.runDataHandler();
}

function page_checkOrg(){
	if(cform.parternerid.value == ""){
		cform.parternername.value = "";
		cform.parternercode.value = "";
	}
}

function page_cleanregionandcity(){
 	cform.regionname.value = "";
 	cform.citycode.value = "";
 	cform.cityname.value = "";
 }

 function page_cleancity(){
 	cform.cityname.value = "";
 }

 var needcheck;
 
 function page_getfilestatus(arrayidx){
	var rowidx = needcheck[arrayidx].value; 
	var fileid = eval("cform.fileid" + rowidx).value;
	var processtype = cform.processtype.value;
	var datahandler = new  DataHandler() ;
	datahandler.add_params("fileid" , fileid, 'Integer');
	datahandler.add_params("processtype" , processtype, 'Integer');
	datahandler.getResult("filestatus" ,"document.cform.filestatus" + rowidx);
	datahandler.getResult("checkstatus" ,"document.cform.checkstatustemp");
	datahandler.add_job("j_getfilestatusbyfileid");
	datahandler.add_function("page_checkfilestatus(" + arrayidx + ")");
	datahandler.runDataHandler();
 }

 function page_onload(){
 	if(cform.cleanrule.value != "") cform.errorlevelshow.disabled = false;
 	needcheck = document.getElementsByName("needcheckrow");
 	page_checkfilestatus();
 }
  
 function page_checkfilestatus(arrayidx){
	 if(!needcheck.length){
		return;
	 }else if(arrayidx == null){
		page_getfilestatus(0);
	 }else if(arrayidx < needcheck.length){
		var rowidx = needcheck[arrayidx].value;
		var filestatus = eval("cform.filestatus" + rowidx).value;
		if(filestatus == 10){
			var fileid = eval("cform.fileid" + rowidx).value;
			document.getElementById("rowcheck" + rowidx).innerHTML = '<input type="checkbox" name="fileids" value="' + fileid + '" class="checkbox">';
			document.getElementById("filestatusrow" + rowidx).innerHTML = '\u00A0<%= label.getLabelName("L_Input") %>';
			document.getElementById("checkstatusrow" + rowidx).innerText = cform.checkstatustemp.value;
		}else if(filestatus == 40){
			var fileid = eval("cform.fileid" + rowidx).value;
			document.getElementById("rowcheck" + rowidx).innerHTML = '\u00A0';
			document.getElementById("filestatusrow" + rowidx).innerHTML = '\u00A0<%= label.getLabelName("L_Complete") %>';
			document.getElementById("checkstatusrow" + rowidx).innerText = cform.checkstatustemp.value;
		}
		
		if(arrayidx >= needcheck.length - 1){
			needcheck = document.getElementsByName("needcheckrow");
			setTimeout("page_checkfilestatus()",10000); 
		}else{
			if(filestatus == 10){
				page_getfilestatus(arrayidx);
			}else{
				page_getfilestatus(arrayidx + 1);
			}
		}
	 }
 }
</script>
</head>
<body onload="page_onload()" >
<iframe id="reloadHandler" name="reloadHandler" style="display:none"></iframe>
<% //--------------------------------------  page location --%>
	<%@ include file="/inc/PageLocation.inc" %>
<table width="100%" cellspacing="0" border="0" cellpadding="0">
<form name="cform" method="post" action="<%=contextPath %>/Dispatcher"  target="_self">
	<input type="hidden" name="pagename" value="p_datacleansummary">
	<input type="hidden" name="actionname">
	<custom:hidden property="processtype"/>
	<custom:hidden property="languagecode" scope="session"/>
	<custom:hidden property="checkstatustemp"/>
	<custom:hidden property="datafrequency"/>
   <tr>
    <td> 
      <table width="100%" border="0" cellspacing="0"  onkeydown="if(event.keyCode==13) page_summary('search');">  
         <tr>
          	<td class="td_right"><%= label.getLabelName("L_Province") + label.getLabelName("L_Colon") %></td>
            <td>
            	<custom:text property="regioncode" name="conditionmap" command="notnull" label="L_Province" size="10" onchange="page_changeRegion()"/>
            	<a onclick="javascript:page_selectProvince();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            	<custom:text property="regionname" name="conditionmap" readonly="true" size="20"/>
            </td>
         	<td class="td_right"><%= label.getLabelName("L_City") + label.getLabelName("L_Colon") %></td>
          	<td>
          		<custom:text property="citycode" name="conditionmap" size="10" onchange="page_changeCity()"/>
            	<a onclick="javascript:page_selectCity();"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            	<custom:text property="cityname" name="conditionmap" readonly="true" size="20"/>
            </td>
         </tr>
         <tr>
         	<td class="td_right" ><%= label.getLabelName("L_Partner") + label.getLabelName("L_Colon") %></td>
            <td>
            	<custom:text property="parternercode" name="conditionmap" size="10" onchange="page_changeOrg()"/>
            	<a onclick="popup('<%=contextPath %>/masterdata/ogm/OrgSelect.jsp?<%= OvalTools.randomURL() %>','newwindow','height=450, width=600,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no')"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
            	<custom:text property="parternername" name="conditionmap" readonly="true" size="20"/>
            	<custom:hidden property="parternerid" name="conditionmap"/>
            </td>
         	<td>&nbsp;</td>
         	<td>&nbsp;</td>
         </tr>
         <tr>
         	<td class="td_right" ><%= label.getLabelName("L_CleanType") + label.getLabelName("L_Colon") %></td>
         	<td>
         		<%
         			String rulestr = (String)pageContext.getAttribute("cleanrulestr");
         			if(rulestr == null) rulestr = "";
         		%>
         		<custom:selectdic dictType="DataCleanRule" valueCriteria="<%=rulestr %>" property="cleanrule" name="conditionmap" defaultValue="---------" defaultValueCost="" onchange="page_changecleanrule()"/>
         	</td>
         	<td class="td_right" ><%= label.getLabelName("L_ErrorLevel") + label.getLabelName("L_Colon") %></td>
         	<td>
         		<custom:selectdic dictType="ErrorLevel" property="errorlevel" changedName="errorlevelshow" name="conditionmap" defaultValue="--------" defaultValueCost="" onchange="javascript:cform.errorlevel.value = cform.errorlevelshow.value;" disabled="true"/>
         		<a href="javascript:page_summary('search')"><img src="<%= contextPath %>/images/<%= strLanguageCode %>/go_fy.gif" border="0" style="border: 1 solid #000000"></a>
         		<custom:hidden property="errorlevel" name="conditionmap"></custom:hidden>
         	</td>
         </tr>
       </table>
    </td>
  </tr>
  <tr> 
    <td> 
      <table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
         <tr  class="deepblue-left"> 
            <td width="5%" class="title_center"><custom:checkbox property="checkall" styleClass="checkbox" onclick="page_checkall()"/></td>
            <td width="*" class="title_center"><%= label.getLabelName("L_filename")%></td>
            <td width="20%" class="title_center"><%= label.getLabelName("L_Partner") %></td>
            <!--<td width="5%" class="title_center"><%= label.getLabelName("L_BatchNumber") %></td>-->
            <td width="5%" class="title_center"><%= label.getLabelName("L_TotalData") %></td>
            <td width="5%" class="title_center"><%= label.getLabelName("L_DeleteNum") %></td>
            <td width="5%" class="title_center"><%= label.getLabelName("L_FileStatus") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_CheckStatus") %></td>
            <td width="10%" class="title_center"><%= label.getLabelName("L_AcceptDate") %></td>
         </tr>
         <%
             int j = 0;
             String strClassType = new String(); 
             Vector totalsummary = (Vector)pageContext.getAttribute("totalsummary");
             if(totalsummary == null) totalsummary = new Vector();
          %>
          <logic:iterate id="summary" collection="<%= totalsummary %>">                      
         <%
            HashMap summaryMap = (HashMap)pageContext.getAttribute("summary");
            if(summaryMap == null) summaryMap = new HashMap();
            String strIsChecked = new String("");
            
            if(j%2 == 1){
              strClassType = "td-listrom";             
            }else{                    
              strClassType = "";
            }
              
            j++;
            String jstr = "" + j;
          %>
           <tr onmouseover="this.className='tr-over'" onmouseout="this.className='<%=JspHelper.filterNull(strClassType)%>'" class="<%=JspHelper.filterNull(strClassType)%>">
            <td class="title_center" id="rowcheck<%=j %>">
            	<%Integer filestatus = (Integer)summaryMap.get("filestatus"); 
            	  if(filestatus.intValue() == 60){
            	%>
            	<custom:hidden property="needcheckrow" value="<%=jstr%>"/>
            	<custom:hidden property="fileid" name="summary" colIndex="<%=new Integer(j) %>"/>
            	<custom:hidden property="filestatus" name="summary" colIndex="<%=new Integer(j) %>"/>
              	<img src="<%= contextPath %>/images/<%= strLanguageCode %>/loadinglit.gif">
              	<%}else{ %>
              	<custom:checkbox property="fileid" styleClass="checkbox" name="summary" changedName="fileids"/>
              	<%} %>
            </td>
            <td>&nbsp;<A onclick="page_detail('<custom:write property="fileid" name="summary"/>')"><custom:write property="filename" name="summary"/></A></td>
            <td>&nbsp;<custom:write property="orgname" name="summary"/></td>
            <!--<td>&nbsp;<custom:write property="batchno" name="summary" nbsp="true"/></td>-->
            <td>&nbsp;<custom:write property="totalqty" name="summary" nbsp="true"/></td>
            <td>&nbsp;<custom:write property="deleteqty" name="summary" nbsp="true"/></td>
            <td id="filestatusrow<%=j %>">&nbsp;<custom:write property="filestatus" name="summary" nbsp="true" dictType="Status"/></td>
            <td>&nbsp;<A onclick="page_checkstatus('<custom:write property="fileid" name="summary"/>','checkstatusrow<%=j %>')" id="checkstatusrow<%=j %>"><custom:write property="checkstatus" name="summary" nbsp="true"/></A></td>
            <!--<td>&nbsp;<custom:write property="receivedate" name="summary" nbsp="true" dataType="date" dataFormat="yyyy-MM-dd"/></td>-->
			<td>&nbsp;<custom:write property="createdate" name="summary" dataType="date" nbsp="true" dataFormat="yyyy-MM-dd HH:mm:ss"/></td>
          </tr>
          </logic:iterate>
      <% //--------------------------------------  flipping page --%>
      <%@ include file="/inc/SummaryAction.inc" %>
      </table>
      <table width="100%" cellspacing="0" cellpadding="0">
      	<tr>
      		<td><%= label.getLabelName("L_UploadFileNum") + label.getLabelName("L_Colon") + (Integer)pageContext.getAttribute("count") %></td>
      	</tr>
        <tr> 
          <td class="summary_top"></td>
        </tr>
        <tr> 
          <td class="td_center">
            <a onclick="page_dataclean()"><custom:button type="1" label="L_DataClean" imgsrc="edit.gif" border="0" style="width:80"/></a>
            <a onclick="page_datacleanall()"><custom:button type="1" label="L_DataCleanAll" imgsrc="delete.gif" border="0" style="width:100"/></a>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  </form>
</table>
</body>
</html>